from datetime import datetime

from ..exts import db

now = datetime.now()
sj = now.strftime("%Y-%m-%d %H:%M:%S")

class User(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    username = db.Column(db.String(16), unique=True, nullable=False)
    password = db.Column(db.String(32), nullable=False)
    reg_time = db.Column(db.DateTime, default=sj)
    phone = db.Column(db.String(11), unique=True)
    avatar = db.Column(db.String(128))
    isDel = db.Column(db.Boolean(), default=False)

    # friends = db.relationship("Friend", backref="user", lazy=True, foreign_keys="uid")

    def save_user(self):
        db.session.add(self)
        db.session.commit()


class Friend(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)

    uid = db.Column(db.Integer, db.ForeignKey('user.id'))
    fid = db.Column(db.Integer, db.ForeignKey('user.id'))
